<template>
	<view class="page-container">
		<!-- 1. 用户信息区（蓝色背景） -->
		<view class="user-info-container">
			<view class="user-bg"></view>
			<view class="user-info">
				<view class="avatar-name">
					<image class="avatar" src="/static/images/avatar.jpg" mode="widthFix"></image>
					<view class="name-phone">
						<text class="name">{{userInfo.nickname}}</text>
						<!-- <text class="phone">18888888888</text> -->
					</view>
				</view>
				<image class="setting-icon" src="/static/setting.png" mode="widthFix"></image>
			</view>
		</view>

		<!-- 2. 名片功能区（嵌入蓝色背景） -->
		<view class="function-list">
			<view class="function-item" @click="toBalance">
				<text>余额</text>
				<view class="balance-info">
					<text class="balance">0.03元</text>
					<uni-icons type="right" size="16"></uni-icons>
				</view>
			</view>
		</view>

		<!-- 3. 订单管理区 -->
		<view class="order-container">
			<!-- 订单标题栏 -->
			<view class="order-header">
				<text class="title">我的订单</text>
				<text class="all-btn" @click="toAllOrders">全部</text>
			</view>

			<!-- 订单状态标签栏 -->
			<view class="order-tabs">
				<view class="tab-item" @click="switchTab(0)">
					<image style="display:block;width:50rpx;height:50rpx;" src="/static/order.png"></image>
					<text>待支付</text>
					<view class="badge">1</view>
				</view>
				<view class="tab-item" @click="switchTab(0)">
					<image style="display:block;width:50rpx;height:50rpx;" src="/static/order.png"></image>
					<text>待服务</text>
				</view>
				<view class="tab-item" @click="switchTab(1)">
					<image style="display:block;width:50rpx;height:50rpx;" src="/static/order.png"></image>
					<text>已完成</text>
				</view>
				<view class="tab-item" @click="switchTab(2)">
					<image style="display:block;width:50rpx;height:50rpx;" src="/static/order.png"></image>
					<text>已取消</text>
				</view>
			</view>
		</view>

		<!-- 2. 名片功能区（嵌入蓝色背景） -->
		<view class="list"
			style="background-color: #fff;margin: 30rpx 30rpx 10rpx;border-radius: 20rpx;box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);">
			<view class="item"
				style="display: flex;align-items: center;padding: 30rpx;border-bottom: 1px solid #e3e3e3;">
				<view style="width: 50rpx;height: 50rpx;">
					<image style="width: 50rpx;height: 50rpx;" src="/static/service.png"></image>
				</view>
				<view style="margin-left: 20rpx;flex: 1;font-size: 28rpx;">
					<text>服务对象管理</text>
				</view>
				<view>
					<uni-icons type="right" size="16" color="#8a8a8a"></uni-icons>
				</view>
			</view>
			<view class="item" style="display: flex;align-items: center;padding: 30rpx;">
				<view style="width: 50rpx;height: 50rpx;">
					<image style="width: 50rpx;height: 50rpx;" src="/static/service.png"></image>
				</view>
				<view style="margin-left: 20rpx;flex: 1;font-size: 28rpx;">
					<text>分享转发</text>
				</view>
				<view>
					<uni-icons type="right" size="16" color="#8a8a8a"></uni-icons>
				</view>
			</view>
		</view>

		<view class="list"
			style="background-color: #fff;margin: 30rpx 30rpx 10rpx;border-radius: 20rpx;box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);">
			<view class="item"
				style="display: flex;align-items: center;padding: 30rpx;border-bottom: 1px solid #e3e3e3;">
				<view style="width: 50rpx;height: 50rpx;">
					<image style="width: 50rpx;height: 50rpx;" src="/static/service.png"></image>
				</view>
				<view style="margin-left: 20rpx;flex: 1;font-size: 28rpx;">
					<text>我是培护师</text>
				</view>
				<view>
					<uni-icons type="right" size="16" color="#8a8a8a"></uni-icons>
				</view>
			</view>
		</view>

	</view>
</template>

<script setup>
	import {
		ref,
		computed,
		onMounted
	} from "vue";
	import {
		store,
		mutations
	} from '@/uni_modules/uni-id-pages/common/store.js';
	import {
		onShow
	} from '@dcloudio/uni-app';

	const userInfo = computed(() => store.userInfo);

	// 订单标签激活状态
	const activeTab = ref(0)

	// 切换订单标签
	const switchTab = (index) => {
		activeTab.value = index
		// 实际项目中可在此加载对应状态的订单数据
	}

	// 页面跳转方法
	const toCard = () => uni.navigateTo({
		url: '/pages/card/index'
	})
	const toBalance = () => uni.navigateTo({
		url: '/pages/balance/index'
	})
	const toAllOrders = () => uni.navigateTo({
		url: '/pages/orders/all'
	})
	onShow(() => {
		// 获取当前登录状态（依赖 uni-id-pages 的存储）
		const userInfo = uni.getStorageSync('uni-id-pages-userInfo') || {}
		if (!userInfo._id) {
			// 未登录，跳转到登录页（使用 redirectTo 避免返回 tabBar 页）
			uni.redirectTo({
				// #ifdef MP-WEIXIN
				url: "/uni_modules/uni-id-pages/pages/login/login-withoutpwd",
				// #endif 
				// #ifndef MP-WEIXIN
				url: "/uni_modules/uni-id-pages/pages/login/login-withpwd",
				// #endif 
			})
		}
	})
</script>

<style scoped>
	.page-container {
		min-height: 100vh;
		background-color: #f5f5f5;
	}

	/* 用户信息区（蓝色背景） */
	.user-info-container {
		position: relative;
		width: 100%;
		height: 380rpx;
		/* 蓝色背景高度 */
	}

	.user-bg {
		position: absolute;
		width: 100%;
		height: 100%;
		background-color: #2c85ff;
		z-index: 1;
	}

	.user-info {
		position: relative;
		width: 100%;
		height: 100%;
		padding: 60rpx 30rpx 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;
		z-index: 2;
	}

	.avatar-name {
		display: flex;
		align-items: center;
		gap: 20rpx;
	}

	.avatar {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		border: 4rpx solid rgba(255, 255, 255, 0.4);
	}

	.name-phone {
		color: #fff;
	}

	.name {
		font-size: 38rpx;
		font-weight: bold;
		display: block;
		margin-bottom: 10rpx;
	}

	.phone {
		font-size: 28rpx;
		opacity: 0.9;
	}

	.setting-icon {
		width: 44rpx;
		height: 44rpx;
	}

	/* 名片功能区（嵌入蓝色背景） */
	/* 名片功能区（嵌入蓝色背景）- 可选优化 */
	.function-list {
		background-color: #fff;
		border-radius: 20rpx;
		margin: -60rpx 30rpx 0;
		/* 可选：将底部内间距从20rpx调整为30rpx，增加功能区自身底部空间 */
		padding: 30rpx 30rpx 30rpx;
		box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
		z-index: 10;
		position: relative;
	}

	.function-item {
		height: 80rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1rpx solid #f1f1f1;
		font-size: 32rpx;
		color: #333;
	}

	.function-item:last-child {
		border-bottom: none;
	}

	.function-item image {
		width: 26rpx;
		height: 26rpx;
		margin-left: 10rpx;
	}

	.balance-info {
		display: flex;
		align-items: center;
		color: #ff4d4f;
	}

	.balance {
		margin-right: 10rpx;
	}

	/* 订单管理区 - 核心修改：添加顶部外间距 */
	.order-container {
		background-color: #fff;
		border-radius: 20rpx;
		/* 核心：增加30rpx顶部外间距，实现与功能区的分离，可按需调整数值 */
		margin: 30rpx 30rpx 10rpx;
		padding: 30rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}

	.order-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 30rpx;
		padding-bottom: 20rpx;
		border-bottom: 1px solid #e3e3e3;
	}

	.title {
		font-size: 34rpx;
		font-weight: bold;
		color: #333;
	}

	.all-btn {
		font-size: 28rpx;
	}

	/* 订单标签栏 */
	.order-tabs {
		display: flex;
		justify-content: space-between;
		align-items: center;
		/* 关键：让所有标签在垂直方向居中 */
		height: 100rpx;
		/* 固定标签栏高度，避免内容撑高导致的对齐问题 */
	}

	.tab-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 28rpx;
		color: #666;
		padding: 0 5rpx;
		position: relative;
	}

	/* 激活状态样式 */
	/* 	.tab-item:nth-child(1) {
		color: #2c85ff;
		font-weight: 500;
	} */

	.badge {
		position: absolute;
		top: -12rpx;
		right: -20rpx;
		width: 32rpx;
		height: 32rpx;
		background-color: #ff4d4f;
		color: #fff;
		font-size: 20rpx;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	/* 空订单状态 */
	.order-empty {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 60rpx 0 40rpx;
		height: 300rpx;
	}

	.new-order {
		font-size: 28rpx;
		color: #666;
		margin-bottom: 40rpx;
	}

	.empty-img {
		width: 220rpx;
		height: 220rpx;
		margin-bottom: 25rpx;
		opacity: 0.5;
	}

	.empty-text {
		font-size: 28rpx;
		color: #999;
	}
</style>